//
//  ReadInfoViewController.m
//  Lucky28
//
//  Created by zr on 2018/8/3.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ReadInfoViewController.h"

@interface ReadInfoViewController ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UIImageView * contentImage;
@property (nonatomic, weak)UILabel * contentLabel;
//@property (nonatomic ,weak)UITextView * textView;
@property (nonatomic, weak)UIWebView * webView;

@end

@implementation ReadInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
   
    self.view.backgroundColor = [UIColor whiteColor];
   
    [self setupNav];
    [self setupUI];
}

- (void)setupNav{
    
    self.title = @"阅读";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0, 0, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}

- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = self.titleString;
    titleLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    titleLabel.textColor = [UIColor blackColor];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xC9C9C9);
    
    self.lineView = lineView;
    
    [self.view addSubview:self.lineView];
    
    
    UIImageView * contentImage = [UIImageView new];
    
    [contentImage sd_setImageWithURL:self.url placeholderImage:ImageNamed(@"tu1")];
    contentImage.backgroundColor = [UIColor whiteColor];
    
    self.contentImage = contentImage;
    
    [self.view addSubview:self.contentImage];
    
    
//    UILabel * contentLabel = [UILabel new];
//
//    contentLabel.text = self.contentString;
//    contentLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
//    contentLabel.textColor = [UIColor blackColor];
//    contentLabel.numberOfLines = 0;
//
//    self.contentLabel = contentLabel;
//
//    [self.view addSubview:self.contentLabel];
    
    
//    UITextView *textView =[[UITextView alloc] init];
//    textView.backgroundColor= [UIColor whiteColor];
//    textView.text = self.contentString;
//    textView.textColor = [UIColor blackColor];
//    textView.editable = NO;
//    textView.font = [UIFont systemFontOfSize:14 * SCREENH6];
//
//    self.textView = textView;
//
//    [self.view addSubview:self.textView];
    
    
    UIWebView *webView = [[UIWebView alloc] init];
    webView.scalesPageToFit = YES;
    //    webView.delegate = self;
    webView.backgroundColor = [UIColor whiteColor];
    NSURL *urlPath = [NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath];
    
    [webView loadHTMLString:self.contentString baseURL:urlPath];
    
    self.webView = webView;
    
    [self.view addSubview:self.webView];

}


- (void)viewDidLayoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(12 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(40 * SCREENH6);
    }];
    
    [self.contentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(5 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(208 * SCREENH6);
    }];
    
//    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
//        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
//        make.top.mas_equalTo(self.contentImage.mas_bottom).offset(10 * SCREENH6);
//    }];
    
//    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
//        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
//        make.bottom.mas_equalTo(self.view);
//        make.top.mas_equalTo(self.contentImage.mas_bottom).offset(5 * SCREENH6);
//    }];
    
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(self.contentImage.mas_bottom).offset(5 * SCREENH6);
    }];
}


- (void)backToView{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
